package com.pipe.servicepipe.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pipe.commonutils.PageResult;
import com.pipe.commonutils.R;
import com.pipe.servicepipe.annotation.OperationAnnotation;
import com.pipe.servicepipe.entity.PipeCustomer;
import com.pipe.servicepipe.entity.vo.PipeCustomerQuery;
import com.pipe.servicepipe.service.PipeCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * <p>
 * 客户表 前端控制器
 * </p>
 *
 * @author hetao
 * @since 2020-07-12
 */
@RestController
@RequestMapping("/pipe/customer")
@Api(tags = "PipeCustomerController", description = "客户管理")
public class PipeCustomerController {
    @Resource
    private PipeCustomerService pipeCustomerService;

    /**
     * 添加客户
     * @param customer
     */
    @PostMapping("save")
    @ApiOperation("添加客户")
    @OperationAnnotation("添加客戶")
    public R saveCustomer(@RequestBody PipeCustomer customer) {
        this.pipeCustomerService.save(customer);
        return R.ok().message("添加客户成功");
    }

    /**
     * 删除客户
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除客户")
    @OperationAnnotation("删除客户")
    public R deleteCustomer(@PathVariable(value = "id") String id) {
        this.pipeCustomerService.removeById(id);
        return R.ok().message("删除客户成功");
    }

    /**
     * 查询客户
     */
    @PostMapping
    @ApiOperation("分页查询")
    @OperationAnnotation("分页查询客戶")
    public R queryCustomerByPage(@ApiParam(required = false,value = "查询条件")
                                    @RequestBody PipeCustomerQuery customerQuery ) {
        Page<PipeCustomer> pageParam  = new Page<>(customerQuery.getPageNum(),customerQuery.getPageSize());
        this.pipeCustomerService.findCustomerByPage(pageParam,customerQuery);
        PageResult pageResult = new PageResult(pageParam);
        return R.ok().message("查询成功").data("result",pageResult);
    }
    /**
     * Excel批量导入
     */
    @PostMapping("excelImport/customers")
    @ApiOperation("客户批量导入")
    @OperationAnnotation("Excel批量导入客户数据")
    public R excelImportCustomers(MultipartFile multipartFile) {
        //hetao_todo Excel导入
        return null;
    }

    /**
     * Excel批量导出
     */
    @PostMapping("excelExport/customers")
    @ApiOperation("客户批量导入")
    @OperationAnnotation("Excel批量导入客户数据")
    public R excelExportCustomers(MultipartFile multipartFile) {
        //hetao_todo Excel导出
        return null;
    }
}

